package br.com.lumis.ims.service.cloud.dataprovider;

import java.util.Iterator;
import java.util.List;

import lumis.doui.source.ISourceData;
import lumis.doui.source.TabularData;
import lumis.doui.table.TableDataProvider;
import lumis.doui.table.TableSource;
import lumis.portal.PortalException;
import lumis.portal.authentication.SessionConfig;
import lumis.util.ITransaction;
import lumis.util.PortalUtil;
import br.com.lumis.ims.model.Balanceador;
import br.com.lumis.ims.service.ELBService;
import br.com.lumis.ims.service.cloud.util.ImsRequestParameters;

import com.amazonaws.auth.AWSCredentials;

public class BalanceadorDataProvider  extends TableDataProvider {

	public BalanceadorDataProvider() throws PortalException {
		super();		
	}
	
	@Override
	public void loadData(SessionConfig sessionConfig, TableSource source,
			ITransaction transaction) throws PortalException {
		AWSCredentials credentials = ImsRequestParameters.getCredentials(sessionConfig, transaction);
		TabularData tabularData = source.getData();
					
		List<Balanceador> balanceadores = new ELBService().getBalanceadores(credentials);
		Iterator<Balanceador> itBalanceadores = balanceadores.iterator();
		while(itBalanceadores.hasNext()) {					
			ISourceData sourceData = tabularData.addRow();
			
			Balanceador balanceador = itBalanceadores.next();
			sourceData.put(ImsRequestParameters.ID, PortalUtil.generateNewGuid());
			sourceData.put(ImsRequestParameters.NOME, balanceador.getNome());
						
		}				
	}

	
}
